<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
//include('../../system/libraries/Form_validation.php');
class MY_Form_validation extends CI_Form_validation{

	function array_errors(){
		$array_error =array();
		foreach($this->_field_data as $key=>$value){
			if(strlen($value['error'])>0)
			$array_error[]=$key;
		}
		return $array_error;

	}

	function date_is_valid($date){
		$format = 'DD/MM/YYYY';
		if(strlen($date) >= 8 && strlen($date) <= 10){
			$separator_only = str_replace(array('M','D','Y'),'', $format);
			$separator = $separator_only[0];
			if($separator){
				$regexp = str_replace($separator, "\\" . $separator, $format);
				$regexp = str_replace('MM', '(0[1-9]|1[0-2])', $regexp);
				$regexp = str_replace('M', '(0?[1-9]|1[0-2])', $regexp);
				$regexp = str_replace('DD', '(0[1-9]|[1-2][0-9]|3[0-1])', $regexp);
				$regexp = str_replace('D', '(0?[1-9]|[1-2][0-9]|3[0-1])', $regexp);
				$regexp = str_replace('YYYY', '\d{4}', $regexp);
				$regexp = str_replace('YY', '\d{2}', $regexp);
				if($regexp != $date && preg_match('/'.$regexp.'$/', $date)){
					foreach (array_combine(explode($separator,$format), explode($separator,$date)) as $key=>$value) {
						if ($key == 'YY') $year = '20'.$value;
						if ($key == 'YYYY') $year = $value;
						if ($key[0] == 'M') $month = $value;
						if ($key[0] == 'D') $day = $value;
					}
					if (checkdate($month,$day,$year)) return true;
				}
			}
		}

		$this->set_message('date_is_valid', $this->CI->lang->line("date_is_valid"         ));
		return false;
	}

}

?>
